package com.blockchain.console.servlets.trading.xlb.xxcs;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blockchain.common.enums.IsPass;
import com.blockchain.console.service.trading.TradingManage;
import com.blockchain.console.service.trading.entity.CyljEntity;
import com.blockchain.console.service.trading.query.CyljQuery;
import com.blockchain.console.servlets.trading.AbstractTradingServlet;
import com.blockchain.framework.http.servlet.annotation.Right;
import com.blockchain.framework.service.ServiceSession;
import com.blockchain.util.parser.EnumParser;
import com.blockchain.util.parser.IntegerParser;

@Right(id = "C_TRADING_UPDATEXXCS", name = "虚拟币管理-参数-编辑")
public class UpdateXxcs extends AbstractTradingServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void processGet(HttpServletRequest request, HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		int id = IntegerParser.parse(request.getParameter("id"));
		TradingManage tsradingManage = serviceSession.getService(TradingManage.class);
		CyljEntity x = tsradingManage.getXxcs(id);
		request.setAttribute("x", x);
		forwardView(request, response, getClass());
	}

	@Override
	protected void processPost(final HttpServletRequest request, final HttpServletResponse response,
			final ServiceSession serviceSession) throws Throwable {
		TradingManage tsradingManage = serviceSession.getService(TradingManage.class);
		int id = IntegerParser.parse(request.getParameter("id"));
		int bid = IntegerParser.parse(request.getParameter("bid"));
		CyljQuery c=new CyljQuery() {
			
			@Override
			public IsPass getXs() {
				return EnumParser.parse(IsPass.class, request.getParameter("xs"));
			}
			
			@Override
			public int getPx() {
				return IntegerParser.parse(request.getParameter("px"));
			}
			
			@Override
			public String getMc() {
				return null;
			}
			
			@Override
			public String getDz() {
				return null;
			}
			
			@Override
			public int getBid() {
				return IntegerParser.parse(request.getParameter("bid"));
			}


			@Override
			public IsPass getSfdxxs() {
				 return EnumParser.parse(IsPass.class, request.getParameter("dxxs"));
			}

			@Override
			public String getNr() {
				return request.getParameter("nr");
			}

			@Override
			public String getLinkNameOrParamEn() {
				return request.getParameter("paramEn");
			}

			@Override
			public String getLinkNameOrParamTw() {
				return request.getParameter("paramTw");
			}
		};

		tsradingManage.updateXxcs(id, bid, c);
		String url = getController().getURI(request, XxcsList.class) + "?bid=" + bid;
		sendRedirect(request, response, url);
	}

}
